﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeiboFilter.Models;
using WeiboFilter.DAL;
using WeiboFilter.SinaWeibo;
using System.Text;
namespace WeiboFilter
{
    public partial class CustomerPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["oauth_token"] == null && Session["customer"] == null)
            {
                Response.Write("<script>alert('请先登录！');window.location.href='Login.aspx';</script>");
            }
        }

        //修改密码
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            CustomerDAL cDAL = new CustomerDAL();
            Customer c = cDAL.GetCustomerById(Session["customer"].ToString());
            if (c.c_pwd.Trim() != txtPassword.Text.Trim())
            {
                //弹出错误信息
                return;
            }
            c.c_pwd = txtNewPwd.Text;
            cDAL.UpdateCustomer(c);
            //弹出恭喜密码修改成功
        }

        protected void btnSinaToDB_Click(object sender, EventArgs e)
        {
            if (Session["oauth_token"] == null)
            {
                lblInfo.Text = string.Format("失败！离线用户无法操作");
                return;
            }

            //调用SINATODB
            GetDataFromSina gd = new GetDataFromSina(Session["oauth_token"].ToString(), Session["oauth_token_secret"].ToString());
            CustomerDAL cD = new CustomerDAL();
            Customer c = cD.GetCustomerById(Session["customer"].ToString());
            string t_since_id = c.since_id;
            int num = gd.getStatuses(ref t_since_id, Session["customer"].ToString());
            c.since_id = t_since_id;
            cD.UpdateCustomer(c);
            lblInfo.Text = string.Format("成功！有{0}条微博存入数据库", num);

        }

        protected void btnBackUp_Click(object sender, EventArgs e)
        {
            if (Session["oauth_token"]==null)
                return;

            GetDataFromSina gd = new GetDataFromSina(Session["oauth_token"].ToString(), Session["oauth_token_secret"].ToString());
            //中间那条就变夹层了


        }
    }
}